package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.mapper.ApArticleContentMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.wemedia.pojos.WmNews;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 陈辉
 * @data 2023 15:40
 */
@Service
@Transactional
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {
    /**
     * 文章上下架
     * @param wmNews
     */
    @Override
    public void updateByMap(WmNews wmNews) {
        boolean isDown = false;          // 没下架：上架状态
        if (wmNews.getEnable() == 0){
            //下架
            isDown = true;
        }

        //修改ap_article_config的is_down属性值就可以了
        update(Wrappers.<ApArticleConfig>lambdaUpdate().set(ApArticleConfig::getIsDown,isDown)
                .eq(ApArticleConfig::getArticleId,wmNews.getArticleId()));
    }
}
